home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / A Project&20812682001.psc / cProgressBar2.cls < prev    next >
Encoding:
Visual Basic class definition  |  2000-12-28  |  7.3 KB  |  227 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4.   Persistable = 0  'NotPersistable
  5.   DataBindingBehavior = 0  'vbNone
  6.   DataSourceBehavior  = 0  'vbNone
  7.   MTSTransactionMode  = 0  'NotAnMTSObject
  8. END
  9. Attribute VB_Name = "clsProgressBar"
  10. Attribute VB_GlobalNameSpace = False
  11. Attribute VB_Creatable = True
  12. Attribute VB_PredeclaredId = False
  13. Attribute VB_Exposed = False
  14. Option Explicit
  15.  
  16. Dim m_TextBefore As String
  17. Dim m_TextAfter As String
  18.  
  19. Dim m_ShowStatus As Boolean
  20. Dim m_bHorizontal As Boolean
  21. Dim m_bBackwards As Boolean
  22. Dim m_BackColor As Long
  23. Dim m_ForeColor As Long
  24.  
  25.  
  26. Public Property Get Horizontal() As Boolean
  27.     Horizontal = m_bHorizontal
  28. End Property
  29. Public Property Let Horizontal(ByVal New_Horizontal As Boolean)
  30.     m_bHorizontal = New_Horizontal
  31. End Property
  32.  
  33. Public Sub ProgressSteppedBar(picProgress As PictureBox, ByVal Part As Single, ByVal Whole As Single)
  34.   Dim Counter As Integer, x As Integer, y As Integer
  35.   Dim lTextTop As Long
  36.   Dim lTextWidth As Long
  37.   Dim iPercent As Single
  38.   
  39.     With picProgress
  40.         .BorderStyle = 0
  41.         .AutoRedraw = True
  42.         .DrawMode = 13 '// Copy Pen
  43.         .ScaleMode = 3
  44.         .BackColor = m_BackColor
  45.         .ForeColor = m_ForeColor
  46.         .FontBold = True
  47.         .Visible = True
  48.     End With
  49.  
  50.     Counter = 10
  51.     If Part > 0 And Whole > 0 Then
  52.         iPercent = CSng(Part) / CSng(Whole)
  53.         If m_bHorizontal Then
  54.             For x = 3 To iPercent * (picProgress.ScaleWidth - 6) Step 3
  55.                 y = x
  56.                 If m_bBackwards Then y = picProgress.ScaleWidth - 6 - x
  57.                 Counter = Counter + 3
  58.                 If Counter >= 8 Then
  59.                     picProgress.Line (y, 3)-(y + 6, picProgress.ScaleHeight - 4), picProgress.ForeColor, BF
  60.                     Counter = 0
  61.                 End If
  62.             Next x
  63.         Else
  64.             For x = 3 To iPercent * (picProgress.ScaleHeight - 6) Step 3
  65.                 y = picProgress.ScaleHeight - 6 - x
  66.                 If m_bBackwards Then y = x
  67.                 Counter = Counter + 3
  68.                 If Counter >= 8 Then
  69.                     picProgress.Line (3, y)-(picProgress.ScaleWidth - 4, y + 6), picProgress.ForeColor, BF
  70.                     Counter = 0
  71.                 End If
  72.             Next x
  73.         End If
  74.     End If
  75.     
  76.     '/* Draw 3D boarder */
  77.     picProgress.DrawMode = 13 '/* Copy Pen
  78.     picProgress.Line (0, 0)-(picProgress.ScaleWidth, picProgress.ScaleHeight), vb3DDKShadow, B
  79.     picProgress.Line (1, picProgress.ScaleHeight - 1)-(picProgress.ScaleWidth, picProgress.ScaleHeight - 1), vb3DHighlight
  80.     picProgress.Line (picProgress.ScaleWidth - 1, 1)-(picProgress.ScaleWidth - 1, picProgress.ScaleHeight), vb3DHighlight
  81.     
  82.     picProgress.Refresh
  83.     
  84. End Sub
  85. Public Sub ProgressBar(picStatus As PictureBox, ByVal Part As Single, ByVal Whole As Single)
  86.   Dim fPercent As Single
  87.   Dim iX As Integer
  88.   Dim iY As Integer
  89.   Dim iWidth As Integer
  90.   Dim iHeight As Integer
  91.   Dim sCaption As String
  92.     
  93.     On Local Error Resume Next
  94.     With picStatus
  95.         .AutoRedraw = True
  96.         .ScaleMode = 1
  97.         .BorderStyle = 0
  98.         .BackColor = m_BackColor
  99.         .ForeColor = m_ForeColor
  100.         .FontBold = False
  101.         .Visible = True
  102.     End With
  103.  
  104.     If Whole > 0 Then
  105.         '/* calculate the percentage from current value and total value
  106.         fPercent = Part / Whole
  107.         If m_ShowStatus Then
  108.             sCaption = CStr(Part) & " of " & CStr(Whole) & Format(fPercent, " (0%)")
  109.         End If
  110.     Else
  111.         fPercent = 0
  112.     End If
  113.     sCaption = IIf(m_TextBefore > vbNullString, m_TextBefore & " ", vbNullString) & sCaption & IIf(m_TextAfter > vbNullString, " " & m_TextAfter, vbNullString)
  114.     
  115.     iWidth = picStatus.TextWidth(sCaption)
  116.     iHeight = picStatus.TextHeight(sCaption)
  117.     
  118.     '/* Now set iX and iY to the starting location for printing the percentage
  119.     iX = (picStatus.ScaleWidth / 2) - (iWidth / 2)
  120.     iY = (picStatus.ScaleHeight / 2) - (iHeight / 2)
  121.  
  122.     '/* Need to draw a filled box with the picStatus background color to wipe out previous
  123.     '/* percentage display (if any)
  124.     picStatus.DrawMode = 13 '/* Copy Pen
  125.     picStatus.Line (iX, iY)-(iWidth, iHeight), picStatus.BackColor
  126.  
  127.     '/* Back to the center pri position and pri the text
  128.     picStatus.CurrentX = iX
  129.     picStatus.CurrentY = iY
  130.     picStatus.Print sCaption
  131.     
  132.     '/* Now fill in the box with the ribbon color to the desired percentage
  133.     '/* Use the "Not XOR" pen so that we change the color of the text to white
  134.     '/* wherever we touch it, and change the color of the background to blue
  135.     '/* wherever we touch it.
  136.     picStatus.DrawMode = 10 '/* Not XOR Pen
  137.     If m_bHorizontal Then
  138.         If fPercent > 0 Then
  139.             If m_bBackwards Then
  140.                 picStatus.Line (picStatus.Width, 0)-(picStatus.Width - (picStatus.Width * fPercent), picStatus.Height), picStatus.ForeColor, BF
  141.             Else
  142.                 picStatus.Line (0, 0)-(picStatus.Width * fPercent, picStatus.Height), picStatus.ForeColor, BF
  143.             End If
  144.         End If
  145.     Else
  146.         If fPercent > 0 Then
  147.             If m_bBackwards Then
  148.                 picStatus.Line (0, 0)-(picStatus.Width, picStatus.Height * fPercent), picStatus.ForeColor, BF
  149.             Else
  150.                 picStatus.Line (0, picStatus.Height)-(picStatus.Width, picStatus.Height - (picStatus.Height * fPercent)), picStatus.ForeColor, BF
  151.             End If
  152.         End If
  153.     End If
  154.     
  155.     '/* Draw 3D boarder */
  156.     picStatus.DrawMode = 13 '/* Copy Pen
  157.     picStatus.ScaleMode = 3
  158.     picStatus.Line (0, 0)-(picStatus.ScaleWidth, picStatus.ScaleHeight), vb3DDKShadow, B
  159.     picStatus.Line (1, picStatus.ScaleHeight - 1)-(picStatus.ScaleWidth, picStatus.ScaleHeight - 1), vb3DHighlight
  160.     picStatus.Line (picStatus.ScaleWidth - 1, 1)-(picStatus.ScaleWidth - 1, picStatus.ScaleHeight), vb3DHighlight
  161.     picStatus.Refresh
  162.     
  163.     On Local Error GoTo 0
  164.  
  165. End Sub
  166.  
  167. Public Property Let Backwards(ByVal New_Backwards As Boolean)
  168.     m_bBackwards = New_Backwards
  169. End Property
  170. Public Property Get Backwards() As Boolean
  171.     Backwards = m_bBackwards
  172. End Property
  173.  
  174. Private Sub Class_Initialize()
  175.     
  176.     m_BackColor = vbWindowBackground
  177.     m_ForeColor = vbHighlight
  178.     
  179.     m_TextBefore = vbNullString
  180.     m_TextAfter = vbNullString
  181.     
  182.     m_bHorizontal = True
  183.     m_ShowStatus = True
  184.     
  185. End Sub
  186.  
  187.  
  188. Public Property Get TextBefore() As String
  189.     TextBefore = m_TextBefore
  190. End Property
  191.  
  192. Public Property Let TextBefore(ByVal vNewValue As String)
  193.     m_TextBefore = TextBefore
  194. End Property
  195.  
  196. Public Property Get TextAfter() As String
  197.     TextAfter = m_TextAfter
  198. End Property
  199.  
  200. Public Property Let TextAfter(ByVal vNewValue As String)
  201.     m_TextAfter = vNewValue
  202. End Property
  203.  
  204. Public Property Get BackColor() As Long
  205.     BackColor = m_BackColor
  206. End Property
  207.  
  208. Public Property Let BackColor(ByVal vNewValue As Long)
  209.     m_BackColor = vNewValue
  210. End Property
  211.  
  212. Public Property Get ForeColor() As Long
  213.     ForeColor = m_ForeColor
  214. End Property
  215.  
  216. Public Property Let ForeColor(ByVal vNewValue As Long)
  217.     m_ForeColor = vNewValue
  218. End Property
  219.  
  220. Public Property Get ShowStatus() As Boolean
  221.     ShowStatus = m_ShowStatus
  222. End Property
  223.  
  224. Public Property Let ShowStatus(ByVal vNewValue As Boolean)
  225.     m_ShowStatus = vNewValue
  226. End Property
  227.